package cz.vargarob.spring.aop.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

import cz.vargarob.spring.aop.util.MyAnnotation;

@Aspect
public class LoggerAspect {

	@Before("cz.vargarob.spring.aop.util.AppPointcuts.printMethod()")
	public void logStatus(){
		System.out.println("Called before the print method");
	}
	
	@Around("cz.vargarob.spring.aop.util.AppPointcuts.printMethod()")
	public void logMethodName(ProceedingJoinPoint jp) throws Throwable{
		System.out.println(" ==== BEGIN ==== " + jp.getSignature().getName() + " ==== ");
		jp.proceed();
		System.out.println(" ==== END ==== " + jp.getSignature().getName() + " ==== ");
	}
	
	@Before("customAnnotatedMethod(myAnnotation)")
	public void logCustomAnnotationName(JoinPoint jp, MyAnnotation myAnnotation){
		System.out.println("XXXXXXXX " + myAnnotation.name());
	}
	
	@Pointcut("execution(@cz.vargarob.spring.aop.util.MyAnnotation * *.*(..)) && @annotation(myAnnotation)")
	public void customAnnotatedMethod(MyAnnotation myAnnotation){}
}
